package com.lagou.task15;

import java.util.*;

public class MapTest {
    public static void main(String[] args) {
        Map<String,String> map1 = new HashMap<>();
        System.out.println("map1 = " + map1);//{}
        map1.put("2","two");
        map1.put("3","three");
        map1.put("1","one");
        System.out.println("map1 = " + map1);//map1 = {1=one, 2=two, 3=three}

//        实现集合元素的查找
        boolean b1 = map1.containsKey("11");
        boolean b2 = map1.containsKey("1");
        boolean b3 = map1.containsValue("four");
        boolean b4 = map1.containsValue("three");
        System.out.println(b1);//false
        System.out.println(b2);//true
        System.out.println(b3);//false
        System.out.println(b4);//true
        //remove
        map1.remove("1");
        System.out.println("map1 = " + map1);

        //获取map集合中所有的key
        Set<String> set1  = map1.keySet();
        Iterator<String> it1 = set1.iterator();
        while (it1.hasNext()){
            String s1 = it1.next();
            System.out.println("s1 = " + s1);
        }
        for (String key:set1
             ) {
            System.out.println("key = " + key);
        }

        Collection<String> values = map1.values();
        for (String s2:values
             ) {
            System.out.println("s2 = " + s2);
        }

        Set<Map.Entry<String, String>> entries = map1.entrySet();
        for (Map.Entry<String, String> e:entries) {
            System.out.println(e);
        }


    }
}
